/*
 * Copyright The OpenTelemetry Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package com.xiashitech.agent.instrumentation.dubbo.common.inst.internal;

import com.alibaba.dubbo.rpc.Result;
import com.xiashitech.agent.instrumentation.dubbo.common.inst.DubboRequest;
//import io.opentelemetry.javaagent.shaded.instrumentation.api.instrumenter.net.InetSocketAddressNetServerAttributesGetter;
import io.opentelemetry.javaagent.shaded.instrumentation.api.instrumenter.network.ClientAttributesGetter;
import io.opentelemetry.javaagent.shaded.instrumentation.api.instrumenter.network.ServerAttributesGetter;

import javax.annotation.Nullable;
import java.net.InetSocketAddress;

// TODO: TO DEL ON NEXT Version (OTEL 版本升级变更 1.29.0)

//public final class DubboNetServerAttributesGetter
//    extends InetSocketAddressNetServerAttributesGetter<DubboRequest> {
//
//  @Override
//  @Nullable
//  public InetSocketAddress getAddress(DubboRequest request) {
//    return request.getRemoteAddress();
//  }
//
//  @Override
//  @Nullable
//  public String transport(DubboRequest request) {
//    return null;
//  }
//}

public final class DubboNetServerAttributesGetter implements ServerAttributesGetter<DubboRequest, Result> {

    @Nullable
    @Override
    public String getServerAddress(DubboRequest request) {
        return request.getUrl().getHost();
    }

    @Override
    public Integer getServerPort(DubboRequest request) {
        return request.getUrl().getPort();
    }

    @Override
    @Nullable
    public InetSocketAddress getServerInetSocketAddress(
            DubboRequest request, @Nullable Result response) {
        return request.getRemoteAddress();
    }

}


